#if UNITY_EDITOR
using System;
using System.IO;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json;

namespace BF
{
    public static class BFTools
    {
        [MenuItem("BF/BF配置检查")]
        //[InitializeOnLoadMethod]
        public static void BFSettingCheck()
        {
            {
                var a = AESSetting.GetInstance();
                var c = Lunch.LaunchSetting.GetInstance();
            }

            {
                PlayerDataInfoTools.CreatPlayerData();
            }

            {
                ConfigConvert.Check();
            }


            {
                string path = Application.dataPath + "/__BF/Editor/Language/";
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }
                string languageFile = path + "Language.csv";
                if (!File.Exists(languageFile))
                {
                    File.WriteAllText(languageFile, "第一行注释,,\nID,Chinese,English\n1001,文案,text");
                }
            }

            AssetDatabase.Refresh();
        }

        [MenuItem("BF/更新BF")]
        public static void UpdateBF()
        {
            {
                string path = new DirectoryInfo(Application.dataPath).Parent.FullName + "/Packages/manifest.json";
                if (File.Exists(path))
                {
                    string json = File.ReadAllText(path);

                    JObject jo = JObject.Parse(json);

                    JObject joLock = jo["lock"] as JObject;
                    if (joLock != null && joLock.ContainsKey("com.lingxin.bf"))
                    {
                        joLock.Remove("com.lingxin.bf");
                    }
                    json = jo.ToString(Formatting.Indented);
                    File.WriteAllText(path, json);
                }
            }

            {
                string path = new DirectoryInfo(Application.dataPath).Parent.FullName + "/Packages/packages-lock.json";
                if (File.Exists(path))
                {
                    string json = File.ReadAllText(path);

                    JObject jo = JObject.Parse(json);

                    JObject joLock = jo["dependencies"] as JObject;
                    if (joLock != null && joLock.ContainsKey("com.lingxin.bf"))
                    {
                        joLock.Remove("com.lingxin.bf");
                    }

                    json = jo.ToString(Formatting.Indented);
                    File.WriteAllText(path, json);
                }
            }

            AssetDatabase.SaveAssets();
            AssetDatabase.Refresh();

            Debug.Log("UpdateBF Finish");
        }
    }
}
#endif
